﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Game
{
    public partial class Settings : Form
    {
        public Settings()
        {
            InitializeComponent();
        }
        Game.FormLoad fl = new FormLoad();
        
        private int slvtrainingdiff;
        private int gamediff;
        private int combatdiff;
        private int _allowincest;
        private int _trainerpregg;
        private int _tenticalrape;

        private void Settings_Load(object sender, EventArgs e)
        {
            this.settingsImage.SizeMode = PictureBoxSizeMode.StretchImage;
            //this.settingsImage.Image = fl.settingsImage;
            this.settingsImage.Image = Game.Properties.Resources.lolipee1;
            Handlers.DBManager dbm = new Handlers.DBManager();
            DataTable dt = dbm.DT("SELECT * FROM `Settings`");
            foreach (DataRow dr in dt.Rows)
            {
                #region Difficulty Check Mark
                if ((int)dr[1] == 0)
                {
                    Diff_Easy.Checked = true;
                }
                else if ((int)dr[1] == 1)
                {
                    Diff_Medium.Checked = true;
                }
                else if ((int)dr[1] == 2)
                {
                    Diff_Hard.Checked = true;
                }
                #endregion
                #region Combat Difficulty Check Mark
                if ((int)dr[5] == 0)
                {
                    cmbt_Easy.Checked = true;
                }
                else if ((int)dr[5] == 1)
                {
                    cmbt_Medium.Checked = true;
                }
                else if ((int)dr[5] == 2)
                {
                    cmbt_Hard.Checked = true;
                }
                #endregion
                #region Slave Training Difficulty Check Mark
                if ((int)dr[6] == 0)
                {
                    slvt_Easy.Checked = true;
                }
                else if ((int)dr[6] == 1)
                {
                    slvt_Medium.Checked = true;
                }
                else if ((int)dr[6] == 2)
                {
                    slvt_Hard.Checked = true;
                }
                else if ((int)dr[6] == 3)
                {
                    slvt_Extreem.Checked = true;
                }
                #endregion
                #region Allow Incest?
                if ((int)dr[2] == 0)
                {
                    allowIncest.Checked = false;
                }
                else if ((int)dr[2] == 1)
                {
                    allowIncest.Checked = true;
                }
                #endregion
                #region Allow Trainer Pregnancy (That means if your female you have a chance to get pregnant)
                if ((int)dr[4] == 0)
                {
                    trainerPregg.Checked = false;
                }
                else if ((int)dr[4] == 1)
                {
                    trainerPregg.Checked = true;
                }
                #endregion
                #region Weather to allow Tentical Rape or Not?
                if ((int)dr[3] == 0)
                {
                    tenticalRape.Checked = false;
                }
                else if ((int)dr[3] == 1)
                {
                    tenticalRape.Checked = true;
                }
                #endregion
            }

        }

        private void btn_SaveSettings_Click(object sender, EventArgs e)
        {
            Handlers.DBManager dbm = new Handlers.DBManager();
            #region Convert information to DB readable
            #region SlaveTraining Diff
            if (slvt_Easy.Checked == true)
            {
                slvtrainingdiff = 0;
            }
            else if (slvt_Medium.Checked == true)
            {
                slvtrainingdiff = 1;
            }
            else if (slvt_Hard.Checked == true)
            {
                slvtrainingdiff = 2;
            }
            else if (slvt_Extreem.Checked == true)
            {
                slvtrainingdiff = 3;
            }
            #endregion
            #region Game Diff
            if (Diff_Easy.Checked == true)
            {
                gamediff = 0;
            }
            else if (Diff_Medium.Checked == true)
            {
                gamediff = 1;
            }
            else if (Diff_Hard.Checked == true)
            {
                gamediff = 2;
            }

            #endregion
            #region Combat Diff
            if (cmbt_Easy.Checked == true)
            {
                combatdiff = 0;
            }
            else if (cmbt_Medium.Checked == true)
            {
                combatdiff = 1;
            }
            else if (cmbt_Hard.Checked == true)
            {
                combatdiff = 2;
            }
            #endregion
            #region Allow Incest?
            if (allowIncest.Checked == true)
            {
                _allowincest = 1;
            }
            else
            {
                _allowincest = 0;
            }
            #endregion
            #region Allow Trainer Pregnancy?
            if (trainerPregg.Checked == true)
            {
                _trainerpregg = 1;
            }
            else
            {
                _trainerpregg = 0;
            }
            #endregion
            #region Allow Tentical Rape
            if (tenticalRape.Checked == true)
            {
                _tenticalrape = 1;
            }
            else
            {
                _tenticalrape = 0;
            }
            #endregion
            #endregion
            try
            {
               //("INSERT INTO `Settings` (`Difficulty`, `IncestAllowed`,`TenticalRapeAllowed`, `TrainerPregnancyAllowed`,`CombatDifficulty`,`SlaveTrainingDifficulty`) VALUES (" + "'" + gamediff + "'," + "'" + _allowincest + "'," + "'" + _tenticalrape + "'," + "'" + _trainerpregg + "'," + "'" + combatdiff + "'," + "'" + slvtrainingdiff + "'" + " WHERE `ID` = `1`);");
               // dbm.OUpdate("UPDATE Settings SET Difficulty = '" + @gamediff + "', IncestAllowed = '" + @_allowincest + "', TenticalRapeAllowed = '" + @_tenticalrape + "', TrainerPregnancyAllowed = '" + @_trainerpregg + "', CombatDifficulty = '" + @combatdiff + "', SlaveTrainingDifficulty = '" + @slvtrainingdiff + "' WHERE ID = '1'");
                dbm.OUpdate("UPDATE Settings SET Difficulty = " + @gamediff + ", IncestAllowed = " + @_allowincest + ", TenticalRapeAllowed = " + @_tenticalrape + ", TrainerPregnancyAllowed = " + @_trainerpregg + ", CombatDifficulty = " + @combatdiff + ", SlaveTrainingDifficulty = " + @slvtrainingdiff + " WHERE ID = 1");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex);
               
            }
            this.Close();
            this.Dispose();
        }

        public void InitalSettings()
        {
           
            
        }
        #region Diff Check to clear if another is selected
        private void Diff_Easy_CheckedChanged(object sender, EventArgs e)
        {
            Diff_Medium.Checked = false;
            Diff_Hard.Checked = false;
            tenticalRape.Enabled = true;
        }

        private void Diff_Medium_CheckedChanged(object sender, EventArgs e)
        {
            Diff_Easy.Checked = false;
            Diff_Hard.Checked = false;
            tenticalRape.Enabled = true;
        }

        private void Diff_Hard_CheckedChanged(object sender, EventArgs e)
        {
            Diff_Easy.Checked = false;
            Diff_Medium.Checked = false;
            tenticalRape.Checked = true;
            tenticalRape.Enabled = false;
        }
        #endregion
        #region Combat Dif check to clear if anoter is selected
        private void cmbt_Easy_CheckedChanged(object sender, EventArgs e)
        {
            cmbt_Hard.Checked = false;
            cmbt_Medium.Checked = false;
        }

        private void cmbt_Medium_CheckedChanged(object sender, EventArgs e)
        {
            cmbt_Easy.Checked = false;
            cmbt_Hard.Checked = false;
         
        }

        private void cmbt_Hard_CheckedChanged(object sender, EventArgs e)
        {
            cmbt_Easy.Checked = false;
            cmbt_Medium.Checked = false;
        }
        #endregion
        #region Slave training diff check to clear if another is selected
        private void slvt_Extreem_CheckedChanged(object sender, EventArgs e)
        {
            slvt_Easy.Checked = false;
            slvt_Hard.Checked = false;
            slvt_Medium.Checked = false;
        }

        private void slvt_Medium_CheckedChanged(object sender, EventArgs e)
        {
            slvt_Hard.Checked = false;
            slvt_Extreem.Checked = false;
            slvt_Easy.Checked = false;
        }

        private void slvt_Easy_CheckedChanged(object sender, EventArgs e)
        {
            slvt_Extreem.Checked = false;
            slvt_Hard.Checked = false;
            slvt_Medium.Checked = false;
        }

        private void slvt_Hard_CheckedChanged(object sender, EventArgs e)
        {
            slvt_Medium.Checked = false;
            slvt_Extreem.Checked = false;
            slvt_Easy.Checked = false;
        }
        #endregion
    }
}
